<?php

namespace Modules\Slider\Http\Controllers;

use foo\bar;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Modules\Slider\Entities\Slider;

class SliderController extends Controller
{
    /**
     * Display a listing of the resource.
     * @return Response
     */
    public function index()
    {
//        dd(123);
        $slider = Slider::get();
//        dd($slider->toArray());
        return view('slider::slider.index',compact('slider'));
    }

    /**
     * Show the form for creating a new resource.
     * @return Response
     */
    public function create()
    {

//        dd(123);
        return view('slider::slider.create');
    }

    /**
     * Store a newly created resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function store(Request $request)
    {
//        dd(123);
//        dd($request->all());
        $slider = $request->all();
        Slider::create($slider);
        session()->flash('success','轮播图添加成功!!!');
        return redirect()->route('slider.index');
    }

    /**
     * Show the specified resource.
     * @return Response
     */
    public function show()
    {
        return view('slider::show');
    }

    /**
     * Show the form for editing the specified resource.
     * @return Response
     */
    public function edit($id)
    {
//        dd(123);
        $slider = Slider::find($id);
        return view('slider::slider.edit',compact('slider'));
    }

    /**
     * Update the specified resource in storage.
     * @param  Request $request
     * @return Response
     */
    public function update(Request $request,$id)
    {
//        dd($id);
        $slider  = Slider::find($id);
        $slider->title = $request->input('title');
        $slider->thumb = $request->input('thumb');
        $slider->url = $request->input('url');
        $slider->is_show = $request->input('is_show');
        $slider->save();
        session()->flash('success','编辑成功!!!');
        return redirect()->route('slider.index');

    }

    /**
     * Remove the specified resource from storage.
     * @return Response
     */
    public function destroy($id)
    {
//        dd($id);
        Slider::destroy($id);
        session()->flash('success','删除成功');
        return back();
    }
}
